package minefak3r;

/**
 *
 * @author Chriss & D4rky!
 */
import java.net.ServerSocket;
import java.net.Socket;

public class Main {

    static ServerSocket s;
    static Socket target;
    static Socket client;
    static String system = "System >>> ";
    static String targetIP = "";
    static int targetPort = 0;
    static SystemPrintStream sp;
    public static final int serverPort = 5555;

    public static void main(String[] args) throws Exception {
        s = new ServerSocket(serverPort);
        sp = new SystemPrintStream();
        sp.SystemOut(system + "Server is started ...");
        waitForClient();
    }

    public static void waitForClient() throws Exception {
        new ConsoleReader(system, System.in, sp).start();
        while (targetIP.equals("") || targetPort == 0) {
            Thread.sleep(2);
        }
        client = s.accept();
        sp.SystemOut(system + "Client is connected ...");
        connectToTarget();
    }

    public static void connectToTarget() throws Exception {
        target = new Socket(targetIP, targetPort);
        sp.SystemOut(system + "Serverconnection established ...");
        new ClientReader(client, target).start();
        new ServerReader(client, target).start();
    }
}
